package com.ceba.test.base.configs;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import com.ceba.cebautils.DateUtil;
import org.apache.commons.lang.StringUtils;

import com.ceba.cebautils.FileUtils;
import com.ceba.test.base.constants.TextConstants;
import com.ceba.test.base.language.resources.WebMessages;

import abc.Config;
import abc.ID;

/**
 * upfile/
 * 	  images
 *    qrcode
 *    sign
 *    stamp
 *    temp
 *    template
 *    toPDF(待定)
 *    user
 * logs/  存放日志文件 debug日志
 *     log
 * s_logs/  存放ERROR日志
 *		/sign.cb  只统计签名记录
 *  /rms/  jsp文件父目录
 * @author Administrator
 *
 */
public class CebaPathUtil {

	private static final String WEB_ROOT = "ep";

	protected static String CONTEXT_PATH = "/" + WEB_ROOT + "/";//项目访问路径

	//所有文件存放目录
	protected static String UPLOAD_PATH = Config.UPLOAD_PATH + CONTEXT_PATH;

	protected static String uploadBashFilePath = "upfile";

	protected static String temp = "temp";

	protected static String images = "images";

	protected static String sign = "sign";

	protected static String sql = "sql";

	protected static String cusresoues = "cusresoues";

	protected static String template = "template";

	protected static String qrcode = "qrcode";

	protected static String stamp = "stamp";

	protected static String fm = "fm";

	protected static String user = "user";

	protected static String license = "license";



	protected static String toPDF = "toPDF";
	//日志
	protected static String LOGS = "logs";

	//错误日志
	protected static String S_LOGS = "s_logs";

	//JSP文件父目录名称
	protected static String RMS = "rms";

	protected static String LIBS = "libs";

	//签名记录
	protected static String SIGN_CB = "sign.cb";

	protected static String DB_LOG = "dblog.txt";
	//透明图片
	private static String transPic = uploadBashFilePath + "/images/null.png";
	/**
	 * 目录模式下附件展示时的做的标识
	 */
	protected static String SIGNED = "signed";

	//虚拟目录
	private static String VIRTUAL_uploadBashFilePath = uploadBashFilePath + "/";

	//签名后虚拟目录
	protected static String VIRTUAL_SIGN_PATH_FOLDER = uploadBashFilePath + "/" + sign + "/";


	//缓存文件虚拟路径
	protected static String VIRTUAL_TEMP_FOLDER = uploadBashFilePath + "/" + temp + "/";



	//各个公司的sql虚拟路径
	protected static String VIRTUAL_SQL_FOLDER = uploadBashFilePath + "/" + sql + "/";

	//图片虚拟路径
	protected static String VIRTUAL_IMAGE_FOLDER = uploadBashFilePath + "/" + images + "/";


	//用户文件虚拟路径
	protected static String VIRTUAL_USER_FOLDER = uploadBashFilePath + "/" + user + "/";


	protected static String VIRTUAL_LICENSE = uploadBashFilePath + "/" + license + "/";



	//模板文件虚拟路径
	protected static String VIRTUAL_TEMPLATE_FOLDER = uploadBashFilePath + "/" + template + "/";


	protected static String VIRTUAL_TOPDF_FOLDER = uploadBashFilePath + "/" + toPDF + "/";

	protected static String VIRTUAL_QRCODE_FOLDER =  uploadBashFilePath + "/" + qrcode + "/";

	//备份数据库的物理路径
	private static String BACKUP_DATABASE_PHYSICAL_FILE_FOLER = CebaConfig.BACKUP_PATH;


	//各个公司的sql文件
	private static String SQL_FOLDER = UPLOAD_PATH + RMS + "/" + sql;
	public static String getSqlFolder() {
		return SQL_FOLDER;
	}

	//自定义规则资源配置文件路径
	private static String CUS_FOLDER = UPLOAD_PATH + uploadBashFilePath + "/" + cusresoues + "/";

	//基础版文件存储物理位置
	protected static String SIGN_FM_FOLDER = VIRTUAL_SIGN_PATH_FOLDER + fm + "/";


	public static String systemValitPath() {
		return Config.UPLOAD_PATH + WebMessages.getContextPath();
	}


	//日志路径 -- DEBUG
//	private static String LOGS_PHYSICAL_FILE_FOLDER() {
//		return getPhysicalWebUploadPath() + LOGS + "/";
//	}
//
//	//日志路径 -- ERROR
//	private static String S_LOGS_PHYSICAL_FILE_FOLDER() {
//		return getPhysicalWebUploadPath() + S_LOGS + "/";
//	}

	//获取项目物理存放文件的总目录
//	public static String getPhysicalWebUploadPath() {
//		return UPLOAD_PATH;
//	}

	/**
	 * jsp文件父目录名称
	 */
	public static String getJSPDirName() {
		return RMS;
	}

	/**
	 * 获取项目目录
	 *
	 * @return
	 */
	public static String getProjectContextPath() {
		return CONTEXT_PATH;
	}

	public static String getUploadBashFilePathName() {
		return uploadBashFilePath;
	}

	/**
	 * ep
	 *
	 * @return
	 */
	public static String getWebRootName() {
		return WEB_ROOT;
	}

	/**
	 * 获取/upfile/路径
	 *
	 * @return
	 */
	public static String getVirtualUpfilePathName() {
		return uploadBashFilePath + "/";
	}

	/**
	 * 取得 D://eq3.3.2Workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps
	 *
	 * @return
	 */
	public static String getPhyscalRootPath() {
		return Config.UPLOAD_PATH;
	}

	//透明图虚拟位置upfile/images/signno.png
	public static String getVisualtransPic() {
		return transPic;
	}



	public static void main(String[] args) {
		System.out.println(getPhyscalRootPath());
	}





	//获取相对导出路径
	public static String getDownLoadToExcelPath(String verPath) {
		return uploadBashFilePath + "/" + temp + "/" + verPath;
	}






	//获取图片的虚拟路径
	public static String getVirtualPicPath() {
		return VIRTUAL_IMAGE_FOLDER;
	}




	//获取手写体的章路径
	public static String getWritePicPath(String vierPath) {
		return CONTEXT_PATH + vierPath;
	}


	/*
	 * 获取印章图片相对路径
	 */
	public static String getVirtualStampPicPathByFilePath(String filePath) {
		return uploadBashFilePath + "/" + images + "/" + new File(filePath).getName();
	}

	public static String getVirtualStampUserPathByFilePath(String filePath) {
		return uploadBashFilePath + "/" + user + "/" + CebaConfig.ANDMIN_USER_ID + "/" + new File(filePath).getName();
	}

	public static String getVirtualStampTempPathByFilePath(String filePath) {
		return uploadBashFilePath + "/" + temp + "/" + new File(filePath).getName();
	}


	public static String getVirtualStampTempPath(String fileName) {
		return uploadBashFilePath + "/" + images + "/" + fileName;
	}


	//获取缓存目录的虚拟路径
	public static String getVirtualTempPath() {
		return VIRTUAL_TEMP_FOLDER;
	}

	//获取总目录的虚拟路径
	public static String getVirtualUpfilePath() {
		return VIRTUAL_uploadBashFilePath;
	}




	//模板文件的虚拟路径
	public static String getVirtualTemplateFolder() {
		return VIRTUAL_TEMPLATE_FOLDER;
	}



	//TOPDF文件的虚拟路径
	public static String getVirtualToPDFFolder() {
		return VIRTUAL_TOPDF_FOLDER;
	}




	//各个公司的sql文件虚拟路径
//	public static String getVirtualSqlFolder() {
//
//		String path = VIRTUAL_SQL_FOLDER;
//		if (!new File(path).exists()) {
//			new File(path).mkdirs();
//		}
//		return path;
//	}







	//获取用户文件虚拟路径
	public static String getVirtualUserFilePathByUserIdAndFileNameTime(String userId, String fileName, String time) {
		return VIRTUAL_USER_FOLDER + userId + "/" + time + "/" + fileName;
	}


	//获取日期图片虚拟存放路径
	public static String getVirtualPicDirPath(String userId) {
		String path = uploadBashFilePath + "/" + user + "/" + userId + "/";
		return path;
	}

	/**
	 * 获取虚拟图片路径
	 *
	 * @param userId
	 * @return
	 */
	public static String getVirtualPicPath(String userId) {
		return "/" + userId + "/" + TextConstants.DATA_TABLES + "/";
	}

	/**
	 * 获取照片管理路径
	 *
	 * @param userId
	 * @return
	 */
	public static String getPictureDirPath(String userId) {
		return "/" + userId + "/" + TextConstants.PIC_MANAGE + "/";
	}

	/**
	 * 签名目录
	 */
	public static String getSignDirPath(String userId) {
		return "/sign/" + userId + "/";
	}


	/**
	 * 报告模板目录
	 */
	public static String getReportTemplatePath(String userId) {
		return "/" + userId + "/" + TextConstants.REPORT_TEMPLATES + "/";
	}

	public static String getReportFileDirPath(String userId, String reportId) {
		return "/" + userId + "/" + reportId + "/";
	}

	//根据报告ID获取含有公章的文档目录
//	public static String getPhysicalStampFolderByReportId(String reportId) {
//		String path = STAMP_FOLDER + reportId + "/";
//		if (!new File(path).exists()) {
//			new File(path).mkdirs();
//		}
//		return path;
//	}





	public static String getSignResordPathName() {
		return SIGN_CB;
	}



	public static String getDBBackPath() {
		String path = BACKUP_DATABASE_PHYSICAL_FILE_FOLER;
		if (!new File(path).exists()) {
			new File(path).mkdirs();
		}
		return path;
	}





	/**
	 * 虚拟拷贝目录-此文件都不存在与数据库中
	 *
	 * @return
	 */
	public static List<String> getNeedCopyDir() {
		// 个性签名图片user  模板template  日志logs  s_logs
		List<String> pathList = new ArrayList<>();
		pathList.add("/" + VIRTUAL_USER_FOLDER);
		pathList.add("/" + VIRTUAL_TEMPLATE_FOLDER);
		pathList.add("/" + VIRTUAL_IMAGE_FOLDER);//BE版特殊
		return pathList;
	}

	//自定义规则资源配置文件路径
	public static String getPhysicalCusFolder() {
		if (!new File(CUS_FOLDER).exists()) {
			new File(CUS_FOLDER).mkdirs();
		}
		return CUS_FOLDER;
	}


}
